#!/usr/bin/env python

import vtk
import sys
import cv
from vtk.util.colors import tomato

if __name__ == '__main__':
    if len(sys.argv) > 1:
        f = open(sys.argv[1], "r")
    if f == None:
        print "Error in reading file"
        exit(-1)
    
    cube = vtk.vtkCubeSource()
    cube.SetXLength(1)
    cube.SetYLength(1)
    cube.SetZLength(1)
    
    cubeMapper = vtk.vtkPolyDataMapper()
    cubeMapper.SetInputConnection(cube.GetOutputPort())
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)   

    for line in f:
        tokens = line.split(" ")
        x = int(tokens[0])
        y = int(tokens[1])
        z = int(tokens[2])
        i = float(tokens[3])
        
        if(i>1):
            cubeActor = vtk.vtkActor()
            cubeActor.SetMapper(cubeMapper)
            cubeActor.GetProperty().SetColor(tomato)
            cubeActor.GetProperty().SetOpacity(i / 150)
            cubeActor.SetPosition(x, y, z)
            ren.AddActor(cubeActor)
        #cubeActor.GetProperty().SetEdgeVisibility(True)
        #cubeActor.GetProperty().SetEdgeColor(1,1,1)

        
    axes = vtk.vtkAxesActor()
    widget = vtk.vtkOrientationMarkerWidget()
    widget.SetOutlineColor(0.9300, 0.5700, 0.1300)
    widget.SetOrientationMarker(axes)
    widget.SetInteractor(iren)
    #widget.SetViewport( 0.0, 0.0, 0.4, 0.4 )
    widget.SetEnabled(1)
    #widget.InteractiveOn()
    
    f.close()
    ren.SetBackground(0, 0, 0)
    renWin.SetSize(200, 200)
    iren.Initialize()
    ren.ResetCamera()
    ren.GetActiveCamera().Zoom(1.5)
    renWin.Render()
    iren.Start()	
        
